/*
 * This code was written by Bear Giles <bgiles@coyotesong.com>and he
 * licenses this file to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Any contributions made by others are licensed to this project under
 * one or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 * 
 * Copyright (c) 2012 Bear Giles <bgiles@coyotesong.com>
 */
package com.invariantproperties.crypto.encryptionServer;

import java.math.BigInteger;

/**
 * Interface that defines methods that can be used to encrypt or decrypt values
 * in the database.
 * 
 * Design question: should we have separate interfaces for encryption and
 * decryption?
 * 
 * Design question: should we have a single rekey() method instead of one for
 * each datatype? This would require encoding the datatype into the ciphertext
 * somehow.
 * 
 * @author bgiles@coyotesong.com
 */
public interface EncryptionService {

    /**
     * Encrypt a string.
     */
    String encryptString(String plaintext,
            EncryptionServiceAuthenticationInfo auth);

    /**
     * Decrypt a string.
     */
    String decryptString(String ciphertext,
            EncryptionServiceAuthenticationInfo auth);

    /**
     * Rekey a string.
     */
    String rekeyString(String ciphertext,
            EncryptionServiceAuthenticationInfo auth);

    /**
     * Encrypt an Integer.
     */
    String encryptInteger(Integer plaintext,
            EncryptionServiceAuthenticationInfo auth);

    /**
     * Decrypt an Integer.
     */
    Integer decryptInteger(String ciphertext,
            EncryptionServiceAuthenticationInfo auth);

    /**
     * Rekey an Integer.
     */
    String rekeyInteger(String ciphertext,
            EncryptionServiceAuthenticationInfo auth);

    /**
     * Encrypt a Long.
     */
    String encryptLong(Long plaintext, EncryptionServiceAuthenticationInfo auth);

    /**
     * Decrypt a Long.
     */
    Long decryptLong(String ciphertext, EncryptionServiceAuthenticationInfo auth);

    /**
     * Rekey a Long.
     */
    String rekeyLong(String ciphertext, EncryptionServiceAuthenticationInfo auth);

    /**
     * Encrypt a Numeric.
     */
    String encryptNumeric(BigInteger plaintext,
            EncryptionServiceAuthenticationInfo auth);

    /**
     * Numeric a Numeric.
     */
    BigInteger decryptNumeric(String ciphertext,
            EncryptionServiceAuthenticationInfo auth);

    /**
     * Rekey a Numeric.
     */
    String rekeyNumeric(String ciphertext,
            EncryptionServiceAuthenticationInfo auth);

    /**
     * Encrypt a Double.
     */
    String encryptDouble(Double plaintext,
            EncryptionServiceAuthenticationInfo auth);

    /**
     * Double a Double.
     */
    Double decryptDouble(String ciphertext,
            EncryptionServiceAuthenticationInfo auth);

    /**
     * Rekey a Double.
     */
    String rekeyDouble(String ciphertext,
            EncryptionServiceAuthenticationInfo auth);
}
